<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商城商品')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mallProduct-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">产品名称：</label>
                <div class="col-sm-8">
                    <input name="productName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">默认展示价格：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">SKU：</label>
                <div class="col-sm-8">
                    <textarea name="skuStr" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">门市价格：</label>
                <div class="col-sm-8">
                    <input name="targetMoney" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">运费模板：</label>
                <div class="col-sm-8">
                    <input name="postage" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最多购买数量：</label>
                <div class="col-sm-8">
                    <input name="maxBuy" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最多可用积分：</label>
                <div class="col-sm-8">
                    <input name="useScore" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最少使用积分：</label>
                <div class="col-sm-8">
                    <input name="minScore" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">已购买金额：</label>
                <div class="col-sm-8">
                    <input name="alreadyMoney" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">销量：</label>
                <div class="col-sm-8">
                    <input name="supportNum" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品简述：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="sketch">
                    <div class="summernote" id="sketch"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品期限：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品图片以;分割：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="images">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="images" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">发布状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'releaseStatus_' + dict.dictCode}" name="releaseStatus" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                        <label th:for="${'releaseStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否推荐：</label>
                <div class="col-sm-8">
                    <input name="isRecommend" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否热门：</label>
                <div class="col-sm-8">
                    <input name="isHot" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商家ID，为空自营：</label>
                <div class="col-sm-8">
                    <input name="merchantId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">字典中的分类(一级)：</label>
                <div class="col-sm-8">
                    <input name="type1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">字典中的分类(二级)：</label>
                <div class="col-sm-8">
                    <input name="type2" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">字典中的分类(三级)：</label>
                <div class="col-sm-8">
                    <input name="type3" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">成本价：</label>
                <div class="col-sm-8">
                    <input name="costPrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商品来源连接：</label>
                <div class="col-sm-8">
                    <input name="source" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商品的供货商：</label>
                <div class="col-sm-8">
                    <input name="supplierName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">一级分销奖金：</label>
                <div class="col-sm-8">
                    <input name="fenxiao" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">二级分销奖金：</label>
                <div class="col-sm-8">
                    <input name="fenxiao2" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品详细：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="content">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备用：</label>
                <div class="col-sm-8">
                    <input name="param1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备用2：</label>
                <div class="col-sm-8">
                    <input name="param2" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">Y是N否：</label>
                <div class="col-sm-8">
                    <input name="deleted" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/mallProduct"
        $("#form-mallProduct-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-mallProduct-add').serialize());
            }
        }

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });
    </script>
</body>
</html>